home *** CD-ROM | disk | FTP | other *** search
/ BMUG Newsletter 1997 Spring / BMUG Spring 1997 Newsletter (1997).bin / Newletter PD Collection / PowerPC / Strip 1.0a1 ƒ / Source Kit ƒ / Strip68K / StripFile.cpp < prev   
Text File  |  1994-06-20  |  4KB  |  170 lines

  1. /*    stripfile.cpp
  2.  *
  3.  *        This contains the actual strip code. There are two versions of this
  4.  *    file, one for the 68K version, and one for the PPC version
  5.  */
  6.  
  7. #include "Strip.h"
  8.  
  9. /************************************************************************/
  10. /*                                                                        */
  11. /*    Error Display Code                                                    */
  12. /*                                                                        */
  13. /************************************************************************/
  14.  
  15. /*    DisplayAlert
  16.  *
  17.  *        Display the alert, given the application name and message
  18.  */
  19.  
  20. static void DisplayAlert(FSSpec *file, short id, short code)
  21. {
  22.     unsigned char buffer[256];
  23.     unsigned char codeStr[32];
  24.     
  25.     GetIndString(buffer,128,id);
  26.     if (code) {
  27.         NumToString(code,codeStr);
  28.         ParamText(file->name,buffer,codeStr,NULL);
  29.     } else {
  30.         ParamText(file->name,buffer,NULL,NULL);
  31.     }
  32.     Alert(130,NULL);
  33. }
  34.  
  35. /************************************************************************/
  36. /*                                                                        */
  37. /*    Main entry point                                                    */
  38. /*                                                                        */
  39. /************************************************************************/
  40.  
  41. /*    StripFile
  42.  *
  43.  *        Determine if this file is the correct one by type and temperment;
  44.  *    if it is, then go ahead and strip the code resources and replace them
  45.  *    with one that presents a very simple message.
  46.  */
  47.  
  48. void StripFile(FSSpec *file)
  49. {
  50.     FInfo finfo;
  51.     short appRefNum;
  52.     Handle alert,ditl,code;
  53.     short len,off;
  54.     short err;
  55.     
  56.     /*
  57.      *  Figure out what the file type is.
  58.      */
  59.     
  60.     if (FHasFSSpec) FSpGetFInfo(file,&finfo);
  61.     else HGetFInfo(file->vRefNum,file->parID,file->name,&finfo);
  62.     
  63.     if (finfo.fdType != 'APPL') {
  64.         DisplayAlert(file,1,0);
  65.         return;
  66.     }
  67.     
  68.     /*
  69.      *    Now open this application for modification.
  70.      */
  71.     
  72.     if (FHasFSSpec) appRefNum = FSpOpenResFile(file,fsRdWrPerm);
  73.     else appRefNum = HOpenResFile(file->vRefNum,file->parID,file->name,fsRdWrPerm);
  74.     if (appRefNum == -1) {
  75.         DisplayAlert(file,2,0);
  76.         return;
  77.     }
  78.     
  79.     /*
  80.      *  Is there a code fragment resource?
  81.      */
  82.     
  83.     SetResLoad(false);
  84.     code = Get1Resource('cfrg',0);
  85.     SetResLoad(true);
  86.     if (code == NULL) {
  87.         CloseResFile(appRefNum);
  88.         DisplayAlert(file,5,0);
  89.         return;
  90.     } else ReleaseResource(code);
  91.      
  92.     /*
  93.      *  Determine if the alert resources that I wish to copy are available
  94.      */
  95.      
  96.     SetResLoad(false);
  97.     code = Get1Resource('CODE',0);
  98.     SetResLoad(true);
  99.     if (code == NULL) {
  100.         CloseResFile(appRefNum);
  101.         DisplayAlert(file,4,0);
  102.         return;
  103.     } else ReleaseResource(code);
  104.     
  105.     SetResLoad(false);
  106.     alert = Get1Resource('ALRT',27309);
  107.     SetResLoad(true);
  108.     if (alert != NULL) {
  109.         ReleaseResource(alert);
  110.         CloseResFile(appRefNum);
  111.         DisplayAlert(file,3,0);
  112.         return;
  113.     }
  114.     SetResLoad(false);
  115.     ditl = Get1Resource('DITL',27309);
  116.     SetResLoad(true);
  117.     if (ditl != NULL) {
  118.         ReleaseResource(ditl);
  119.         CloseResFile(appRefNum);
  120.         DisplayAlert(file,3,0);
  121.         return;
  122.     }
  123.     
  124.     /*
  125.      *  Time to do the fixup
  126.      */
  127.     
  128.     len = Count1Resources('CODE');
  129.     for (off = len; off > 0; off--) {
  130.         SetResLoad(false);
  131.         code = Get1IndResource('CODE',off);
  132.         SetResLoad(true);
  133.         SetResAttrs(code,0);
  134.         RemoveResource(code);                    // Remove from this one
  135.         if (0 != (err = ResError())) {
  136.             CloseResFile(appRefNum);
  137.             DisplayAlert(file,6,err);
  138.             return;
  139.         }
  140.         DisposeHandle(code);
  141.     }
  142.     
  143.     alert = GetResource('ALRT',27309);            // Pull it from me
  144.     DetachResource(alert);
  145.     AddResource(alert,'ALRT',27309,"\pAdded by Strip68K");
  146.     WriteResource(alert);
  147.     ReleaseResource(alert);
  148.     
  149.     ditl = GetResource('DITL',27309);
  150.     DetachResource(ditl);
  151.     AddResource(ditl,'DITL',27309,"\pAdded by Strip68K");
  152.     WriteResource(alert);
  153.     ReleaseResource(alert);
  154.     
  155.     code = GetResource('c68K',128);
  156.     DetachResource(code);
  157.     AddResource(code,'CODE',0,"\pAdded by Strip68K");
  158.     WriteResource(code);
  159.     ReleaseResource(code);
  160.     
  161.     code = GetResource('c68K',129);
  162.     DetachResource(code);
  163.     AddResource(code,'CODE',1,"\pAdded by Strip68K");
  164.     WriteResource(code);
  165.     ReleaseResource(code);
  166.     
  167.     UpdateResFile(appRefNum);
  168.     CloseResFile(appRefNum);
  169. }
  170.